package com.rongshu.view.discovery.presenter;

import android.content.Context;

import com.rongshu.api.RetorfitService;
import com.rongshu.utils.Common;
import com.rongshu.utils.UserInfoUtils;
import com.rongshu.view.base.mvp.BasePresenter;
import com.rongshu.view.base.mvp.INetBean;
import com.rongshu.view.base.mvp.INetView;
import com.rongshu.view.discovery.bean.SerialChapterListResponse;
import com.rongshu.view.discovery.bean.SerialListResponse;

import java.util.HashMap;
import java.util.Map;

import rx.Subscriber;
import rx.functions.Action0;

/**
 * created by zhengweis on 2019/3/8.
 * description：
 */
public class SerialDetailsPresenter extends BasePresenter<INetView> {

    public SerialDetailsPresenter(Context context) {
        super(context);
    }

    public void getSerialChapterList(int serialize_id, int pageIndex, int pageSize) {
        Map<String, Object> map = new HashMap<>();
        map.put("user_id", UserInfoUtils.getUserId());
        map.put("serialize_id", serialize_id);
        map.put("pageIndex", pageIndex);
        map.put("pageSize", pageSize);
        RetorfitService.getSerialChapterList(UserInfoUtils.getUserId(), serialize_id, pageIndex, pageSize,
                Common.encryptionSign(map)).compose(getView().<SerialChapterListResponse>bindToLife())
                .doOnSubscribe(new Action0() {
                    @Override
                    public void call() {

                    }
                }).subscribe(new Subscriber<SerialChapterListResponse>() {
            @Override
            public void onCompleted() {

            }

            @Override
            public void onError(Throwable e) {

            }

            @Override
            public void onNext(SerialChapterListResponse object) {
                if (object.getErrCode() == 0) {
                    getView().success(object, 0);
                }
            }
        });
    }
}
